package com.cardbaobao.cardbabyclient.widget.banner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.model.Banner;
import com.cardbaobao.cardbabyclient.utils.DensityUtil;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;
import com.cardbaobao.cardbabyclient.widget.banner.BannerViewHolder;

/**
 * Created by Jiangzx on 15:31.
 */

public class ScalePagerView implements BannerViewHolder<Banner.CarouselFigureListBean> {
    private ImageView mImageView;
    private int radian;
    @Override
    public View createView(Context context) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_transformer_pager,null);
        mImageView= (ImageView) view.findViewById(R.id.iv);
        this.radian=DensityUtil.dp2px(6.0f);
        return view;
    }

    @Override
    public void onBind(Context context, int position,final Banner.CarouselFigureListBean data) {
        ImageLoaderUtil.displayImageWithPlaceHolder(URLUtil.CBB_IMG_URL+data.getImage(),
                mImageView,R.mipmap.img_default_banner,radian);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onBannerItemClicked(data);
                }
            }
        });
    }

    private OnBannerItemClickedListener listener;
    public void setOnBannerItemClickedListener(OnBannerItemClickedListener listener){
        this.listener=listener;
    }

    public interface OnBannerItemClickedListener {
        void onBannerItemClicked(Banner.CarouselFigureListBean bean);
    }
}
